package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/per")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    @RequiresPermissions(value = {"列表权限","per:list"},logical = Logical.OR)
    public String list(QueryObject queryObject, Model model) {
        PageInfo<Permission> pageInfo = permissionService.selectByQO(queryObject);
        model.addAttribute("pageInfo", pageInfo);
        return "permission/list";
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"删除权限","per:delete"},logical = Logical.OR)
    public String delete(Long perId) {

        permissionService.deleteByPerId(perId);

        return "redirect:/per/list";
    }


    @RequestMapping("/reload")
    @RequiresPermissions(value = {"重新加载列表权限","per:reload"},logical = Logical.OR)
    public String reload() {

        permissionService.reload();
        return "redirect:/per/list";
    }
}
